//
//  MKTabBar.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/7.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit

class MKTabBar: UITabBar {
    override init(frame: CGRect) {
        super.init(frame: frame)
//        self.shadowImage = UIImage.init()
//        self.backgroundImage = UIImage.init(named: "tabBar_bottomBg")
    }
    
    func setupAllTabBarButtonsFrame() -> Void {
        var index:Int = 0
         for tabBarButton in self.subviews {
            if(!(tabBarButton.isKind(of: UIControl.classForCoder())))
            {
               continue;
            }
            self.setupTabBarButtonFrame(tabBarButton: tabBarButton, index: index)
            index += 1
        }
    }
    
    func setupTabBarButtonFrame(tabBarButton:UIView,index:Int) -> Void {
        
        // 计算button的尺寸
        let buttonW:CGFloat = self.width / (CGFloat)(self.items!.count)
        let buttonH:CGFloat = self.height        
        
        tabBarButton.frame = CGRect.init(x: buttonW * CGFloat(index), y: 0, width: buttonW, height: buttonH)
        if(index == 2){
            tabBarButton.y = -8
        }
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.setupAllTabBarButtonsFrame()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
